package com.example.app1;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.example.app1.Util.DateUtil;

import org.w3c.dom.Text;

public class ResponseActivity extends AppCompatActivity implements View.OnClickListener
{

    String resultStr="好的，我这就出去";

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_response);
        Bundle bundle = getIntent().getExtras();
        String sendtime = bundle.getString("sendtime");
        String request=bundle.getString("request");
        String reqStr = String.format("时间：%s\n收到的消息是：%s", sendtime, request);
        TextView tv_recv =  findViewById(R.id.tv_recv);
        tv_recv.setText(reqStr);
        TextView result = findViewById(R.id.tv_result);
        result.setText("要发回的消息是"+ resultStr);
        findViewById(R.id.feedbackBtn).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        Intent intent = new Intent();
        Bundle result = new Bundle();
        result.putString("respondTime", DateUtil.getTimeStr());
        result.putString("response",resultStr);
        intent.putExtras(result);
        //携带意图返回上一个ACtivity，RESULT_OK表示处理成功
        setResult(RESULT_OK,intent);
        //结束当前的界面
        finish();
    }
}
